package com.jisf.driver.controller;

import com.jisf.driver.entity.vo.MenuListVo;
import com.jisf.driver.response.IErrorCode;
import com.jisf.driver.response.Result;
import com.jisf.driver.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 权限表 前端控制器
 * </p>
 *
 * @author jisf
 * @since 2022-04-08
 */
@RestController
@RequestMapping("/driver/menu")
public class MenuController {

    @Autowired
    private IMenuService iMenuService;

    @PostMapping("menuListAside")
    public Result<?> menuListAside(){
        List<MenuListVo> menuList = iMenuService.getMenuListAside();
        return Result.ok(menuList);
    }

    @GetMapping("list")
    @PreAuthorize("hasAnyAuthority('menu:list')")
    public Result<?> menuList(){
        List<MenuListVo> menuListVos = iMenuService.menuList();
        return Result.ok(menuListVos);
    }

    @GetMapping("menuAll")
    @PreAuthorize("hasAnyAuthority('menu:menuAll')")
    public Result<?> menuAll(){
        List<MenuListVo> allMenus = iMenuService.getAllMenus();
        return Result.ok(allMenus);
    }

    @GetMapping("change/status")
    @PreAuthorize("hasAnyAuthority('menu:change:status')")
    public Result<?> menuChangeStatus(@RequestParam Integer menuId,
                                      @RequestParam String status){
        IErrorCode iErrorCode = iMenuService.menuChangeStatus(menuId, status);
        return Result.ok(iErrorCode);
    }

    @GetMapping("change/visible")
    @PreAuthorize("hasAnyAuthority('menu:change:visible')")
    public Result<?> menuChangeVisible(@RequestParam Integer menuId,
                                      @RequestParam String visible){
        IErrorCode iErrorCode = iMenuService.menuChangeVisible(menuId, visible);
        return Result.ok(iErrorCode);
    }

}
